/**
 * 
 */
package fr.toto.menuitem;

import java.awt.Desktop;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.URI;
import javax.swing.JMenuItem;

import com.kokotchy.betaSeriesAPI.model.Episode;

import fr.toto.constantes.Constantes;
import fr.toto.exceptions.ProcessException;

/**
 * @author tshepo
 * 
 */
public class BetaSeriesLinkMenuItem extends JMenuItem implements Constantes {

	/**
	 * 
	 */
	private static final long serialVersionUID = 5798587763246784363L;
	private String url;

	/**
	 * 
	 */
	public BetaSeriesLinkMenuItem(Episode e) {
		super(MESSAGES.getString("BetaSeriesLinkMI"));

		url = BetaSeriesURI + "episode/" + e.getShowUrl() + "/"
				+ e.getNb().toLowerCase();

		this.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				try {
					URI uri = new URI(url);
					Desktop.getDesktop().browse(uri);
				} catch (Exception e1) {
					new ProcessException(e1);
				}

			}
		});

	}

	public BetaSeriesLinkMenuItem(String u) {
		super(MESSAGES.getString("BetaSeriesLinkMI"));

		url = BetaSeriesURI + "episode/" + u;

		this.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				try {
					URI uri = new URI(url);
					Desktop.getDesktop().browse(uri);
				} catch (Exception e1) {
					new ProcessException(e1);
				}

			}
		});

	}
}
